package service

import (
	"errors"
	"fmt"
	"github.com/go-xorm/xorm"
	"im/model"
	"log"
)

var DbEngine *xorm.Engine
func init() {
	driverName		:=	"mysql"
	dataSourceName	:=	"root:123456@(127.0.0.1:3306)/chat?charset=utf8"
	err:=errors.New("")
	DbEngine, err=xorm.NewEngine(driverName,dataSourceName)
	if err!=nil && err.Error()!="" {
		log.Fatalln(err.Error())
	}
	//显示执行的sql语句
	DbEngine.ShowSQL(true)
	DbEngine.SetMaxOpenConns(2)
	DbEngine.Sync2(new (model.User))
	fmt.Println("init database OK")
}